<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.util.CodeTableUtil"%>
<%@page import="com.feib.soeasy.model.Payment"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><%=UserUtil.getCurrentMenuItemName() %></title>
	<script type="text/javascript" src="<c:url value='/scripts/jquery/jquery.bgiframe-2.1.2.js'/>"></script>
	<script type="text/javascript">
	<!--	
	$(document).ready(function() {
		
		$('#doQueryBtn').click(function() {
			var errMsg = "";
			var qryPayDueFrom = $('#qryPayDueFrom').val();
			var qryPayDueTo = $('#qryPayDueTo').val();
			var virtualAccount = $('#qryPayment\\.virtualAccount').val();
			var payerId = $('#qryPayment\\.payerId').val();


			<%if ( UserUtil.isBankGroup()){ %>
			var groupNo = $('#group\\.groupNo').val();
			
			if (null == groupNo || 0 == groupNo.length){
				errMsg = errMsg + "業者代號 是必要欄位<br/>";
			}//2011/06/16 jeff Gu  start   修正    業者代號不存在時 查詢錯誤問題
			else if (12 != groupNo.length){
				errMsg = errMsg + "業者代號 為固定長度12碼<br/>";
			}//2011/06/16 jeff Gu  end   修正    業者代號不存在時 查詢錯誤問題
			else
				$('#hidden\\.group\\.groupNo').val(groupNo);
			<%}%>

			/*
			if (null == qryPayDueFrom || 0 == qryPayDueFrom.length){
				errMsg = errMsg + "繳費期限起 是必要欄位<br/>";
			}
			
			if (null == qryPayDueTo || 0 == qryPayDueTo.length){
				errMsg = errMsg + "繳費期限迄 是必要欄位<br/>";
			}
			*/
			if (0 != errMsg.length){
				$("#ajaxErrorMessageDiv").html(errMsg);
				$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'請修正下列錯誤' 
					,width: 300
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				return false;
			}

			$('#hidden\\.qryPayDueFrom').val(qryPayDueFrom);
			$('#hidden\\.qryPayDueTo').val(qryPayDueTo);
			$('#hidden\\.qryPayment\\.virtualAccount').val(virtualAccount);
			$('#hidden\\.qryPayment\\.payerId').val(payerId);
						
			doQueryAction(1);
		});
				
		var dates = $( "#qryPayDueFrom, #qryPayDueTo" ).datepicker({
			defaultDate: "-1m",
			changeMonth: true,
			changeYear: true,
			numberOfMonths: 1,
			dateFormat: 'yy/mm/dd',
			showButtonPanel: true,
			showOn: "both",
			buttonImage: "<c:url value='styles/default/images/calendar.gif'/>",
			buttonImageOnly: true,
			onSelect: function( selectedDate ) {
				var option = this.id == "qryPayDueFrom" ? "minDate" : "maxDate",
					instance = $( this ).data( "datepicker" );
					date = $.datepicker.parseDate(
						instance.settings.dateFormat ||
						$.datepicker._defaults.dateFormat,
						selectedDate, instance.settings );
				dates.not( this ).datepicker( "option", option, date );
			}
		});

		<%if ( UserUtil.isBankGroup()){ %>
		$('#findGroupNoImg').click(function() {
			var groupNo = $('#group\\.groupNo').val();
			
			if (null != groupNo && 0 != groupNo.length){
				var tmpGroupNo = parseInt(groupNo,10);
				if(! isNaN(tmpGroupNo)){
					$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
					$('#hidden\\.qryGroup\\.groupName').val('');
					$('#qryGroup\\.groupNo').val(groupNo);
					$('#qryGroup\\.groupName').val('');
				}
				else{
					$('#hidden\\.qryGroup\\.groupNo').val('');
					$('#hidden\\.qryGroup\\.groupName').val(groupNo);
					$('#qryGroup\\.groupNo').val('');
					$('#qryGroup\\.groupName').val(groupNo);
					$("#queryGroupResultDiv").html('');
				}
				
				$("#findGroupDiv" ).dialog({  
					title:'帳單業者查詢' 
					, width: 600
					, resizable: true
					, modal: true
				});
				
				$('#doAjaxQueryGroupsBtn').click();
			}
			else{
				$('#hidden\\.qryGroup\\.groupNo').val('');
				$('#hidden\\.qryGroup\\.groupName').val('');
				$('#qryGroup\\.groupNo').val('');
				$('#qryGroup\\.groupName').val('');
				$("#queryGroupResultDiv").html('');
				$("#findGroupDiv" ).dialog({  
					title:'帳單業者查詢' 
					, width: 600
					, resizable: true
					, modal: true
				});
			}
	
		});
		
		$('#doAjaxQueryGroupsBtn').click(function() {
			var groupNo = $('#qryGroup\\.groupNo').val();
			var groupName = $('#qryGroup\\.groupName').val();
			$("#queryGroupResultDiv").html('');

			$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
			$('#hidden\\.qryGroup\\.groupName').val(groupName);
			doQueryGroupAction(1);
			
		});
		
		$('#doAjaxCloseGroupsBtn').click(function() {
			$("#findGroupDiv" ).dialog( "destroy" );
		});
		
<%}%>
				
	});
	
	function doQueryAction(pageNumber)
	{
		<%if ( UserUtil.isBankGroup()){ %>
		var groupNo = $('#.group\\.groupNo').val();
		$('#hidden\\.group\\.groupNo').val(groupNo);
		<%}%>
		if (null != pageNumber){
			$('#hidden\\.queryResult\\.pageNumber').val(pageNumber);
			waitingDialog({});
		}
		else {
		}
		$("#queryResultDiv").fadeTo("slow", 0.1);
		
		
		$.ajax({url : "<c:url value='/ajax/Soez1016.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest){
					$("#queryResultDiv").html(data);
				},
			error : function(XMLHttpRequest, textStatus, errorThrown){
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'系統錯誤' 
					,width: 600
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				},
			complete: function(XMLHttpRequest, textStatus){
				closeWaitingDialog();
				$("#queryResultDiv").fadeTo("slow", 1);
			}
		});
	}
	
	function doQueryPaymentsAction(paymentPk)
	{
		$('#hidden\\.qryPayment\\.paymentPk').val(paymentPk);
		
		waitingDialog({});
		$.ajax({url : "<c:url value='/ajax/Soez1016.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryPaymentsItemHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest){
					$("#paymentsItemDiv").html(data);
					$("#paymentsItemDiv" ).dialog({  
						title:'繳費單資料' 
						,width: 600
						, resizable: false
						, modal: true
					});
				},
			error : function(XMLHttpRequest, textStatus, errorThrown){
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
					$("#ajaxErrorMessageDiv" ).dialog({  
						title:'系統錯誤' 
						,width: 600
						, resizable: false
						, modal: true
						, buttons: {
							Ok: function() {
								$( this ).dialog( "close" );
							}
						}
					});
				},
			complete: function(XMLHttpRequest, textStatus){closeWaitingDialog();}
		});
		
		
	}

	
	function doPaymentCanceledConfirmAction(payMentStatus)
	{
		var isDoComfirm = false;
		$('#confirmHiddenFrom input:checkbox.chk').each(function(){               
        	if ( $(this).attr('checked') ){
        		isDoComfirm = true;
        	}
       	});

		if(isDoComfirm){
			$('#hidden\\.qryPayment\\.paymentStatus').val(payMentStatus);
			waitingDialog({});
			
			$.ajax({url : "<c:url value='/ajax/Soez1016.action'/>",
				async : true,
				type : 'POST',
				data : $("#confirmHiddenFrom").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest){
						$("#paymentListDiv").html(data);
					},
				error : function(XMLHttpRequest, textStatus, errorThrown){
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
					$("#ajaxErrorMessageDiv" ).dialog({  
						title:'系統錯誤' 
						,width: 600
						, resizable: false
						, modal: true
						, buttons: {
							Ok: function() {
								$( this ).dialog( "close" );
							}
						}
					});
					},
				complete: function(XMLHttpRequest, textStatus){
					closeWaitingDialog();
					$("#paymentListDiv").fadeTo("slow", 1);
				}
			});				
		}else{
			$("#ajaxErrorMessageDiv").html("至少選擇一筆");
                    $("#ajaxErrorMessageDiv" ).dialog( "destroy" );
                    $("#ajaxErrorMessageDiv" ).dialog({  
                        title:'錯誤訊息' 
                        ,width: 600
                        , resizable: false
                        , modal: true
                        , buttons: {
                            Ok: function() {
                                $( this ).dialog( "close" );
                            }
                        }
                    });
                    return false;
		}
		
	}
	

	<%if ( UserUtil.isBankGroup()){ %>	
		function doQueryGroupAction(pageNumber)
		{
			$('#hidden\\.queryGroupResult\\.pageNumber').val(pageNumber);
			$("#queryGroupResultDiv").fadeTo("slow", 0.1);

			waitingDialog({});
			$.ajax({url : "<c:url value='/ajax/Soez1016.action'/>",
				async : true,
				type : 'POST',
				data : $("#queryGroupHiddenFrom").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest){
						$("#queryGroupResultDiv").html(data);
					},
				error : function(XMLHttpRequest, textStatus, errorThrown){
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
					$("#ajaxErrorMessageDiv" ).dialog({  
						title:'系統錯誤' 
						,width: 600
						, resizable: false
						, modal: true
						, buttons: {
							Ok: function() {
								$( this ).dialog( "close" );
							}
						}
					});
					},
				complete: function(XMLHttpRequest, textStatus){
					if ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent)){
						$("#findGroupDiv" ).dialog( "close" );
						$("#findGroupDiv" ).dialog( "open" );					
					}
					closeWaitingDialog();
					$("#queryGroupResultDiv").fadeTo("slow", 1);
				}
			});
		}
		
		function doGroupNoChanged(groupNo)
		{
			$("#hidden\\.group\\.groupNo").val(groupNo);

			waitingDialog({});
			$.ajax({url : "<c:url value='/ajax/Soez1016.action'/>",
				async : true,
				type : 'POST',
				data : $("#groupNochangedHiddenFrom").serialize(),
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest){
					$('#qryUploadFile\\.formatDefinition\\.formatDefinitionPk').find('option').remove().end().append(data);
					$('#uploadFile\\.formatDefinition\\.formatDefinitionPk').val('');
					},
				error : function(XMLHttpRequest, textStatus, errorThrown){
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
					$("#ajaxErrorMessageDiv" ).dialog({  
						title:'系統錯誤' 
						,width: 600
						, resizable: false
						, modal: true
						, buttons: {
							Ok: function() {
								$( this ).dialog( "close" );
							}
						}
					});
					},
				complete: function(XMLHttpRequest, textStatus){closeWaitingDialog();}
			});
			
		}
	<%}%>
		function doCheckAll(){
			$('#listTable input:checkbox.chk').each(function(){              
	        $(this).attr("checked", true);
	       });
		}
		
		function undoCheckAll(){
			$('#listTable input:checkbox.chk').each(function(){               
	        $(this).attr("checked", false);
	       });
		}
	//-->
	</script>
</head>
<body>
<div id="mainAreaCT">
		<jsp:include page="/includes/path.jsp"/>
		<jsp:include page="/includes/subMenu.jsp"/>
		
	<div id="queryFormDiv">
		<stripes:form id="queryPaymentFrom" beanclass="com.feib.soeasy.action.Soez1016ActionBean" 
			method="post" onsubmit="javascript: return false;">
			
		<table id="queryForm">
			<%if ( UserUtil.isBankGroup()){ %>
			<tr>
				<th>業者代號<span id="mustKeyInStar">**</span></th>
				<td colspan="3">
					<div id="findGroupNoImg"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
					<stripes:text id="group.groupNo" name="group.groupNo" size="12" maxlength="12" />					
					<span id="qryFormatDefinition.group.groupName.span"><c:out value="${actionBean.qryGroup.groupName }"/></span>				
				</td>
			</tr>
			<%} %>
			<tr>
				<th>繳費帳號</th>
				<td>
					<stripes:text id="qryPayment.virtualAccount" 
						name="qryPayment.virtualAccount" size="25" maxlength="25"/>
				</td>
				<th>客戶編號</th>
				<td>
					<stripes:text id="qryPayment.payerId"
						name="qryPayment.payerId" size="20" maxlength="20"/>
				</td>
			</tr>
			<tr>
				<th>繳費期限</th>
				<td colspan="3">
					<stripes:text id="qryPayDueFrom" name="qryPayDueFrom" size="10" maxlength="10" formatPattern="yyyy/MM/dd" readonly="true"/>
					～
					<stripes:text id="qryPayDueTo" name="qryPayDueTo" size="10" maxlength="10" formatPattern="yyyy/MM/dd" readonly="true"/>
				</td>
			</tr>
			<tr>
				<td colspan="4" class="queryFunction">
					<stripes:button id="doQueryBtn" name="doQueryBtn" value="查詢"/>
				</td>
			</tr>
		</table>
		</stripes:form>
	</div><!-- end #queryForm -->
	
	<div id="paymentListDiv" style="display: none;">
	</div>
	
	<!-- 帳單查詢結果  -->
	<div id="queryResultDiv" style="display: none;">
	</div>
	
	<div id="queryHiddenFormDiv" style="display: none;">
		<stripes:form id="queryHiddenFrom" beanclass="com.feib.soeasy.action.Soez1016ActionBean" 
			method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.qryPayDueFrom" name="qryPayDueFrom" formatPattern="yyyy/MM/dd"/>
			<stripes:hidden id="hidden.qryPayDueTo" name="qryPayDueTo" formatPattern="yyyy/MM/dd"/>
			<stripes:hidden id="hidden.qryPayment.virtualAccount" name="qryPayment.virtualAccount"/>
			<stripes:hidden id="hidden.qryPayment.payerId" name="qryPayment.payerId"/>
			<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />			
			<%if ( UserUtil.isBankGroup()){ %>
			<stripes:hidden id="hidden.group.groupNo" name="group.groupNo"/>
			<%} else {%>
			<input type="hidden" id="hidden.group.groupNo" name="group.groupNo" value="<%out.print(UserUtil.getUserGroup().getGroupNo());%>"/>
			<%} %>
			
			
			<input type="hidden" id="method1" name="doAjaxQuery"/>
		</stripes:form>
	</div>

	<!-- 帳單明細查詢 -->
	<div id="paymentsItemDiv" style="display: none;">
	</div>
	<div id="queryFilePaymentsHiddenFormDiv" style="display: none; ">
		<stripes:form id="queryPaymentsItemHiddenFrom" beanclass="com.feib.soeasy.action.Soez1016ActionBean" 
			method="post" onsubmit="javascript: return false;">			
			<stripes:hidden id="hidden.qryPayment.paymentPk" name="qryPayment.paymentPk"/>
			<stripes:hidden id="hidden.qryPayDueFrom" name="qryPayDueFrom" formatPattern="yyyy/MM/dd"/>
			<stripes:hidden id="hidden.qryPayDueTo" name="qryPayDueTo" formatPattern="yyyy/MM/dd"/>
			<stripes:hidden id="hidden.qryPayment.virtualAccount" name="qryPayment.virtualAccount"/>
			<stripes:hidden id="hidden.qryPayment.payerId" name="qryPayment.payerId"/>			
			<input type="hidden" id="method2" name="doAjaxQueryFilePayments"/>
		</stripes:form>
	</div>
	
	<!-- 帳單銷帳 -->	
	<div id="cancelPaymentsItemDiv" style="display: none;">
	</div>
	
	<!-- Message -->
	<div id="ajaxErrorMessageDiv" style="display: none;"></div>

	<%if ( UserUtil.isBankGroup()){ %>
	<!-- 業者代號 查詢 -->
	<div id="findGroupDiv" style="display: none;">
		<div id="queryGroupDiv">
		<table>
			<tr>
				<th>業者代號</th>
				<td><input id="qryGroup.groupNo" type="text" size="12" maxlength="12" /> </td>
			</tr>
			<tr>
				<th>名稱</th>
				<td><input id="qryGroup.groupName" type="text" size="20" /></td>
			</tr>
			<tr>
				<td colspan="2" class="queryFunction">
					<input type="button" value="查詢" id="doAjaxQueryGroupsBtn"/>
					<input type="button" value="離開" id="doAjaxCloseGroupsBtn"/>
				</td>
			</tr>
		</table>
		</div>
		<div id="queryGroupResultDiv" style="display: none;">
		</div>
	</div>
	<div id="queryGroupHiddenFormDiv" style="display: none; ">
		<stripes:form id="queryGroupHiddenFrom" beanclass="com.feib.soeasy.action.Soez1016ActionBean" 
			method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.qryGroup.groupName" name="qryGroup.groupName"/>
			<stripes:hidden id="hidden.qryGroup.groupNo" name="qryGroup.groupNo"/>
			<stripes:hidden id="hidden.queryGroupResult.pageNumber" name="queryGroupResult.pageNumber" />			
			<input type="hidden" id="method4" name="doAjaxQueryGroups"/>
		</stripes:form>
	</div>
	<%} %>
	
</div>
</body>
</html>